<?php


namespace app\admin\controller\ord;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Db;

/**
 * @ControllerAnnotation(title="订单列表")
 */
class Order extends AdminController
{

    use \app\admin\traits\Curd;
    protected $sort = [
        'id'   => 'desc',
    ];

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new \app\admin\model\Order();
        
    }
    
    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $count = $this->model
                ->where($where)
                ->count();
            $list = $this->model
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select();
            foreach ($list as $k => $v){
                $service_technician = Db::name("service_technician")->where("id",$v["service_technician_id"])->find();
                $service_goods = Db::name("service_goods")->where("id",$v["service_goodid"])->find();
                $user = Db::name("user")->where("id",$v["uid"])->find();
                $v['user_name'] = $user['nickname'];
                $v['service_goodsname'] = $service_goods['title'];
                $v['service_name'] = $service_technician['service_name'];
                $list[$k] = $v;
            }
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }

    
    
    /**
    * @NodeAnotation(title="订单详情")
    */
    public function ord_detail()
    {
        $post = $this->request->param();
        $row = Db::name("order")->where("id",$post["id"])->find();
        //项目
        $service_goods = Db::name("service_goods")->where("id",$row["service_goodid"])->field("title,price")->find();
        //地址
        $adderss = Db::name("address")->where("id",$row["address_id"])->find();
        //下单人
        $user = Db::name("user")->where("id",$row["uid"])->field("nickname")->find();
        //达人
        $service_technician = Db::name("service_technician")->where("id",$row["service_technician_id"])->find();

        $row['service_name'] = $service_technician['service_name'];
        $row["service_goodsname"] = $service_goods["title"]; 
        $row["adderss"] = $adderss; 
        $row["nickname"] = $user["nickname"]; 
        $row['service_price'] = $service_goods['price'];
        $row["create_time"] = date("Y-m-d H:i:s",$row["create_time"]);
         
        $this->assign("row",$row);
        return $this->fetch();
    }
 

    
 
} 